package com.zhouchb.test.设计模式.工厂模式;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Create 2023-06-24 22:08
 * @Description
 */
public class SimpleFactory {
    public pizza factory(String name){
            pizza pizza = null;
                if (name.equals("A")){
                    pizza = new A();
                }else if (name.equals("B")){
                    pizza = new B();
                }
                System.out.println(pizza.name());
            return pizza;
    }
}
abstract class pizza {
    public abstract String name();

    public void cut(){
        System.out.println("切割披萨");
    }
    public void box(){
        System.out.println("打包");
    }
}
class A extends pizza{
    @Override
    public String name() {
        return "a披萨";
    }
}
class B extends pizza{

    @Override
    public String name() {
        return "b披萨";
    }
}
class order{
    public order(String name){
        SimpleFactory simpleFactory = new SimpleFactory();
       pizza factory = simpleFactory.factory(name);
       factory.cut();
       factory.box();
    }

}
class order2{
    public order2(String name){
        SimpleFactory simpleFactory = new SimpleFactory();
        pizza factory = simpleFactory.factory(name);
        factory.cut();
        factory.box();
    }

}
class test{
    public static void main(String[] args) {
        order a = new order("A");
        order2 b = new order2("B");

    }
}
